import os

import openai

os.environ["OPENAI_API_KEY"] = "cc84cb87efef3e9903e8a30abf316b62"  # 将个人token替换到这个位置
os.environ["OPENAI_BASE_URL"] = "https://apitoken.ceba.ceshiren.com/openai/v1/"
os.environ["OPENAI_API_BASE"] = "https://apitoken.ceba.ceshiren.com/openai/v1/"


conversation = [
    {"role": "system", "content": "你是一个智能回答小助手"}
]

print("开始聊天吧，输入`exit`退出聊天")
while True:
    user_input = input("You: ")
    if user_input.lower() == "exit":
        break
    conversation.append({"role": "user", "content": user_input})

    response = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=conversation
    )

    bot_response = response.choices[0].message.content
    conversation.append({"role": "assistant", "content": bot_response})
    print(f"小助手: {bot_response}")

